package com.iflytek.utils;

import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @基本功能:
 * @program:FlinkProject
 * @author: 闫哥
 * @create:2023-12-21 15:29:30
 **/
public class HashExample {

    public static void main(String[] args) {
        String input = "Hello, World!";
        long hashedValue = md5Hash(input);
        System.out.println("MD5 hash value: " + hashedValue);
    }

    public static Integer md5Hash(String input) {
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            byte[] hashBytes = digest.digest(input.getBytes(StandardCharsets.UTF_8));

            // Convert the byte array to a BigInteger
            BigInteger hashNumber = new BigInteger(1, hashBytes);

            // Convert the BigInteger to a decimal representation
            //String hashString = hashNumber.toString();


            return  hashNumber.intValue();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }
    }
}
